package com.parking.carsystem.parkingchargesystem.wxapi;

import android.content.Intent;
import android.util.Log;

import com.parking.carsystem.parkingchargesystem.R;
import com.parking.carsystem.parkingchargesystem.activity.BaseActivity;
import com.parking.carsystem.parkingchargesystem.common.Constant;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {

    private IWXAPI mApi;


    @Override
    protected int getContentViewId() {
        return R.layout.activity_pay_result;
    }

    @Override
    public void initView() {
        mApi = WXAPIFactory.createWXAPI(this, Constant.WX_APP_ID);
        mApi.registerApp(Constant.WX_APP_ID);
        mApi.handleIntent(getIntent(), this);
    }

    @Override
    public void initData() {

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        mApi.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq baseReq) {
        Log.e("onResp", "onReq->" + baseReq.toString());
    }

    @Override
    public void onResp(BaseResp baseResp) {
        Log.e("onResp", "onResp->" + baseResp.errCode + baseResp.errStr);
        if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            if (baseResp.errCode == 0) {
                showToast("支付成功");
//                TipManager.toastLong(this, "支付成功");
            } else {
                showToast("支付失败");
//                TipManager.toastLong(this, "支付失败");
            }
            finish();
        }
    }
}
